package szte.objectorgy.collections;

import szte.objectorgy.collections.Iterator;
import szte.objectorgy.collections.LinkedList;
import szte.objectorgy.collections.Queue;
import szte.objectorgy.collections.Stack;
import szte.objectorgy.collections.Vector;

public class MyMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("		VECTOR");
		vectorTest();
		System.out.println("		STACK");
		stackTest();
		System.out.println("		LINKEDLIST");
		linkedListTest();
		System.out.println("		QUEUE");
		queueTest();
	}
	
	public static void vectorTest(){
		Vector<Integer> v = new Vector<Integer>(Integer.class);
		System.out.println("Empty: " + v.isEmpty());
		v.add(1);
		v.add(2);
		v.add(3);
		v.add(4);
		v.add(5);
		v.add(6);
		v.add(7);
		System.out.println("Empty: " + v.isEmpty());
		
		int n = v.size();
		for(int i = 0; i < n; i++){
			System.out.print(v.get(i) + " ");
		}
		System.out.println();
		System.out.println("Contains 10: " + v.contains(10));
		System.out.println("Index of 1: " + v.indexOf(1));
		
		Object[] obj = v.toArray();
		System.out.println("Array[3]: " + obj[3] + ", length: " + obj.length);
		
		v.remove(4);
		v.set(0, 100);
		
		Vector<Integer> u = new Vector<Integer>(Integer.class);
		u.add(1);
		u.add(3);
		v.removeAll(u);
		System.out.println("Remove 4, Set(0, 100), RemoveAll -> 1, 3: ");
		Iterator<Integer> it = v.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();	
		
		v.addAll(u);
		System.out.println("AddAll -> 1, 3: ");
		it = v.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();	
	}
	
	public static void stackTest(){
		Stack<String> s = new Stack<String>(String.class);
		s.push("One");
		s.push("Two");
		s.push("Three");
		s.push("Four");
		System.out.println(s.pop());
		System.out.println(s.pop());
		
		Iterator<String> it = s.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();
	}
	
	public static void linkedListTest(){
		LinkedList<Double> l = new LinkedList<Double>();
		l.add(0.1);
		l.add(0.2);
		l.add(0.3);
		l.add(0.4);
		l.add(0.5);
		Iterator<Double> it = l.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();
		System.out.println("Size: " + l.size());
		
		LinkedList<Double> u = new LinkedList<Double>();
		u.add(0.1);
		u.add(0.5);
		l.removeAll(u);
		LinkedList<Double> v = new LinkedList<Double>();
		v.add(0.01);
		v.add(0.03);
		l.addAll(v);
		System.out.println("RemoveAll 0.1 0.5 AddAll 0.01 0.03: ");
		it = l.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();
		
		l.add(5, 100.0);
		System.out.println("Add(4, 100.0): ");
		it = l.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();
		
		Object[] obj = l.toArray();
		System.out.println("Array[3]: " + obj[3] + ", length: " + obj.length);
	}
	
	public static void queueTest(){
		Queue<Boolean> s = new Queue<Boolean>();
		s.push(true);
		s.push(true);
		s.push(false);
		s.push(false);
		System.out.println(s.pop());
		System.out.println(s.pop());
		
		Iterator<Boolean> it = s.getIterator();
		while(it.hasNext()){
			System.out.print(it.next() + " ");
		}
		System.out.println();
	}
}
